package com.boot.util;

import com.alibaba.fastjson.JSON;
import lombok.Data;

@Data
public class ResultUtils {
    private Integer code;

    private String msg;

    private Object data;

    public static String result(ResultCode resultCode,Object data){
        ResultUtils result = new ResultUtils();
        result.code = resultCode.getCode();
        result.msg = resultCode.getMsg();
        result.data = data;
        return JSON.toJSONString(result);
    }

    public static String success(Object data){
        ResultUtils result = new ResultUtils();
        ResultCode resultCode = ResultCode.SUCCESS;
        result.code = resultCode.getCode();
        result.msg = resultCode.getMsg();
        result.data = data;
        return JSON.toJSONString(result);
    }

    public static String error(Object data){
        ResultUtils result = new ResultUtils();
        ResultCode resultCode = ResultCode.ERROR;
        result.code = resultCode.getCode();
        result.msg = resultCode.getMsg();
        result.data = data;
        return JSON.toJSONString(result);
    }

}

